import { reqGoodsInfo ,reqAddorUpdateShopCart} from "@/api";
import {getUUID} from "@/utils/uuid_token"
const state = {
    goodsInfo: {},
    uuid_token:getUUID()
};
const mutations = {
    GETGOODSINFO(state, value) {
        state.goodsInfo = value
        // console.log(state.categroyList);
    },
};
const actions = {
    //向服务器发请求，获取数据
    async getGoodsInfo(context, value) {
        let result = await reqGoodsInfo(value);
        if (result.code === 200) {
           let a= context.commit('GETGOODSINFO', result.data);
        }
    },
    //将产品添加到购物车中||修改产品数目
    async addorUpdateShopCart(context, {skuId,skuNum}) {
        let result = await reqAddorUpdateShopCart(skuId,skuNum);
        if(result.code==200){
            return 'ok'
        }else{
            console.log(2);
            return Promise.reject(new Error('失败'))
        }
    },
};


const getters = {
    categoryView(state) {
        return state.goodsInfo.categoryView || {}
    },
    skuInfo(state) {
        return state.goodsInfo.skuInfo || {}
    },
    spuSaleAttrList(state) {
        return state.goodsInfo.spuSaleAttrList||[]
    },
};

export default {
    namespaced: true,
    state,
    actions,
    mutations,
    getters
}